<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Merchandise :: Hambaa.com</title>
<link rel="stylesheet" type="text/css" href="jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="styles/Graphitti_style.css" />
<link rel="stylesheet" type="text/css" href="styles/Checkout_ShippingAddress.css" />
	<script type="text/javascript" src="jquery.min.js"/></script>
	<script src="jquery.ui.core.js"></script>
	<script src="jquery.ui.widget.js"></script>
	<script src="jquery.ui.position.js"></script>
	<script src="jquery.ui.menu.js"></script>
	<script src="jquery.ui.autocomplete.js"></script>
<script>
$(document).ready(function(){
	
	$.ajax({url:"rest/data/shoppingCart.php",
	type:'GET',
	success:function(result){
	if(result ){
	//alert(result);
    order = JSON.parse(result);
    count = order.ordercount;
	if (count <=0)
			document.getElementById('table_container').innerHTML=error;
	else{
		var whiteSpace='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		var table=
		'<table border="0" cellpadding="3">'+
		'<tr><td colspan="2"><h1> Order Summary '+whiteSpace+'<span style="font-size:16px;;">EDIT</span></h1></td></tr>';
		/*'<a href = "javascript:void(0)" onclick = "document.getElementById("light").style.display="block";document.getElementById("fade").style.display="block";getShoppingCart()"> View Cart </a>'*/

		
		 var total_quantity = 0;
	                var total_price = 0;
					var delivery='Free';
					var coupon_discount='Not Applied';
					var gift='NA';
					var grand_total=0;
	                var total_savings = 0;
		  for (i = 0; i < count; i++) {
						var j=0;	
						var attributeString='<br>';
						while(order.cart[i].attributes[j]){ 
						
						attributeString+=order.cart[i].attributes[j].attributeName+' : '+order.cart[i].attributes[j].attributeValue+' ';
						//attributeString+=order.cart[i].attributes[j].attributeName+' : <img src="images/attributes/'+order.cart[i].attributes[j].attributeValue+'.gif"> <br>';
						j++;
						}
	                    	
	                    table = 
						table + 
						'<tr align="center">'+
						'<td align="left"><table border="0"><tr><td><img  src="images/tshirts/' + order.cart[i].productId + '.jpg" height="70" width="70"></td><td valign="top"><span style="font-size:18px;">' +order.cart[i].productName+ '</span>'+attributeString+'<br>Qty : '+order.cart[i].quantity+'</td></tr></table>';
						
						table = 
						table + 
						'<td align="left">Rs. ' + order.cart[i].discountPrice * order.cart[i].quantity + '</td>'  + '</tr>';
						table+= '<tr><td colspan=2><hr/></td></tr>';

	                }
		table+='<tr><td align="right">Cart Total</td><td>Rs. '+order.coupons.amount+'</td></tr>';
		if(order.gift.isGift){
		gift='Rs. '+order.gift.amountGiftWrap;
		}
		table+='<tr><td align="right">Gift Wrap</td><td>'+gift+'</td></tr>';
		
			if (order.finalPayment.shippingCharge!=0){
						delivery=order.finalPayment.shippingCharge;
						}
		table+='<tr><td align="right">Delivery Charges</td><td>'+delivery+'</td></tr>';
		if(order.coupons.discountApply=='Y'){
					coupon_discount='Rs. '+order.coupons.discount;
					}
		table+='<tr><td align="right">Coupon discount</td><td>'+coupon_discount+'</td></tr>';
		table+= '<tr><td colspan=2><hr/></td></tr>';	
		table+='<tr><td align="right"><b>Grand Total</b></td><td><b>Rs. '+order.finalPayment.grandTotal+'</b></td></tr>';
		table+='</table>';
		document.getElementById('table_container').innerHTML=table;
	}
	}
	},
	error:function(result){
		alert("error");
	}
	});

		$.ajax({url:"rest/data/readStates.php",
		type:'GET',
		success:function(result){
		var availableStates=[];
			//alert(result);
		availableStates = result.split(",");
		$( "#buyer_state" ).autocomplete({
			source: function(req, response) { 
				var re = $.ui.autocomplete.escapeRegex(req.term); 
				var matcher = new RegExp( "^" + re, "i" ); 
				response($.grep( availableStates, function(item){ 
				return matcher.test(item); }) ); 
			},
			minLength:1
		});
		},
		error:function(result){
			alert("error");
		}
		});
		
$("#buyer_state").blur(function(){
	var buyerState=document.getElementById('buyer_state').value;		 	
	$.ajax({url:"rest/data/readCities.php",
		data :{buyerState:buyerState},
		type:'GET',
		success:function(result){
		var availableCities=[];
		availableCities = result.split(",");
		$( "#buyer_city" ).autocomplete({
			source: function(req, response) { 
				var re = $.ui.autocomplete.escapeRegex(req.term); 
				var matcher = new RegExp( "^" + re, "i" ); 
				response($.grep( availableCities, function(item){ 
				return matcher.test(item); }) ); 
			},
			minLength:1
		});
		},
		error:function(result){
			alert("error");
		}
		});
});		

$("#buyer_state").blur(function(){
	if($(this).val().trim() == ""){
		$("#buyer_city").val("");
	}	
});	


$("#saveorder").click(function(){
var buyerFirstname=document.getElementById('buyer_firstname').value;		 	
var buyerLastname=document.getElementById('buyer_lastname').value;		 	
var buyerAddress1=document.getElementById('buyer_address1').value;		 	
var buyerAddress2=document.getElementById('buyer_address2').value;		 	
var buyerCity=document.getElementById('buyer_city').value;		 	
var buyerState=document.getElementById('buyer_state').value;		 	
var buyerPincode=document.getElementById('buyer_pincode').value;		 	
var buyerEmail=document.getElementById('buyer_email').value;		 	
var buyerContactno=document.getElementById('buyer_contactno').value;

if(validate('alpha','buyer_firstname') && 
	validate('alpha','buyer_lastname') &&
	validate('address','buyer_address1') &&
	validate('alpha','buyer_city') &&
	validate('alpha','buyer_state') &&
	validate('pin','buyer_pincode') &&
	validate('email','buyer_email') &&
	validate('mobile','buyer_contactno')){
	
	}else{
	return;
	}

//alert(buyerContactno);	 	
$.ajax({url:"rest/data/saveorder.php",
type:'GET',
data : {buyerFirstname:buyerFirstname,buyerLastname:buyerLastname,buyerAddress1:buyerAddress1,buyerAddress2:buyerAddress2,buyerCity:buyerCity,buyerState:buyerState,buyerPincode:buyerPincode,buyerEmail:buyerEmail,buyerContactno:buyerContactno},
success:function(result){
	alert(result);
document.getElementById('shippingAddress').style.display = "none";	

document.getElementById('orderConfirmation').style.display = "block";	
	
	var address=buyerFirstname+' '+buyerLastname+'<br>'+buyerAddress1+'<br>Landmark :'+buyerAddress2+'<br>'+buyerCity+'<br>'+buyerState+' '+buyerPincode;
$("#address").html(address);

$("#orderNo").html(result);

$("#email").html(buyerEmail);
alert(result.length);
document.getElementById('pdforderid').value=result;
document.getElementById('pdfemail').value=document.getElementById('buyer_email').value;

},
error:function(result){
	alert("error");
}
});
});
});

function submitform(){
	//alert('hi');
	var formId = document.getElementById('generatePdf');
	formId.action = 'order_summary_pdf.php';
	formId.submit();	

}

function validate(type,testValue){
var emailRegex =/^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$/g;
var mobileRegex =/^[0-9]\d{9}$/g;
var alphaRegex =/^[A-Za-z ]+$/g; 
var addressRegex = /^[^ ][^]+$/g;
var pinRegex =/^[0-9]\d{5}$/g;
var text=document.getElementById(testValue).value;
var idforDisplay = document.getElementById(testValue+'display');
if(type == 'alpha' ){
type=alphaRegex;
}else if (type == 'pin'){
type=pinRegex;
}else if (type == 'address'){
type=addressRegex;
}else if (type == 'mobile'){
type=mobileRegex;
}else{
type=emailRegex;
}
if(type.test(text))
{
idforDisplay.style.visibility="hidden";
return true;
}else {
idforDisplay.style.visibility="visible";
return false;
}
}


</script>

</head>

<body>

<table id="headertable" border="0" align="center" width="950" height="118"  >
<tr >
<td height="114" align="right" valign="bottom">
<a href="index.php"><img src="images/logopng.png" width="103" height="99" /></a></td>
<td align="left" valign="top">
<a href="index.php"><img src="images/hambaa_logo_newjpg.jpg" width="308" height="107" /></a>
</td>
<td valign="top" align="right">
    <table id="containertable" cellpadding="0" cellspacing="0" border="0">
    <tr>
    <td align="right">
        <div id="menulinks">
        <a href="index.php" class="active">Home</a>
        <a href="offers.php">Offers</a>
        <a href="about_us.php">About Us</a>
        <a href="contact_us.php">Contact Us</a>
        </div>
    </td>
    </tr>
    </table></td>
</tr>
</table>


<table id="outertable" border="0" width="950" height="269" align="center" bgcolor="#FFFFFF" cellpadding="5" >

<tr >
<td align="center" valign="top" width="449">

<div id="shippingAddress" style="display:block;;">
<table id="innerright" align="right" border="0" cellpadding="5" width="91%">
<tr>
	<td colspan="2"><h1>Shipping Address</h1></td>
    <td></td>
</tr>
<tr>
    <td width="33%">First Name* </td>
    <td width="49%"><input type="text" name="buyer_firstname" id="buyer_firstname" onblur="validate('alpha','buyer_firstname')" /></td>
    <td width="18%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_firstnamedisplay"/></td>
</tr>
<tr>
	<td width="33%">Last Name* </td><td width="49%"><input type="text" name="buyer_lastname" id="buyer_lastname" onblur="validate('alpha','buyer_lastname')"/>
    <td width="18%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_lastnamedisplay"/></td>
</tr>
<tr>
    <td>Pincode* </td><td><input type="text" maxlength="6" id="buyer_pincode" onblur="validate('pin','buyer_pincode')"/></td>
    <td width="18%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_pincodedisplay"/></td>
<tr>
<tr>
    <td>Address* </td><td><textarea id="buyer_address1" onblur="validate('address','buyer_address1')"></textarea></td>
    <td width="18%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_address1display"/></td>
</tr>
<tr>    
    <td>Landmark : </td><td><input type="text" id="buyer_address2"/></td>
    <td width="18%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_address2display"/></td>
</tr>
<tr>
    <td>City* </td><td><input type="text" id="buyer_city" onblur="validate('alpha','buyer_city')"/></td>
    <td width="18%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_citydisplay"/></td>
</tr>
<tr>        
    <td>State* </td><td><input type="text" id="buyer_state" onblur="validate('alpha','buyer_state')" /></td>
    <td width="18%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_statedisplay"/></td>
</tr>
    <td>e-mail* </td><td><input type="text" id="buyer_email" onblur="validate('email','buyer_email')"/></td>
    <td width="18%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_emaildisplay"/></td>
</tr>
<tr>
    <td>Contact No* </td><td><input type="text" maxlength="10" size="15" id="buyer_contactno" onblur="validate('mobile','buyer_contactno')"/></td>
    <td width="18%"><img src="images/cross.png" style="visibility:hidden;height:15px;width:15px;" id="buyer_contactnodisplay"/></td>
<tr>
    <td colspan="3" align="center"><a href = "#" id="saveorder" class="wishbtn" >Save Address</a></td>
</tr>
</table>
</div>  

</td>
<td width="37" valign="middle" align="center">
<img src="images/vr.png" height="350"/>




</td>
<td width="426"  align="center" valign="top">

<div id="table_container" style="overflow:auto;height:600px;border:0px solid;" >            

</div>
 
<div id="orderConfirmation" style="display:none">

<h1>Order Confirmation</h1>

	<table id="innerright" border="0" cellspacing="5" width="100%" >
    
		
        <tr>
        	<td><h3> Shipping Address </h3></td>
            <td><h4>Your order is succesfully saved</h4></td>
         </tr>
        <tr><td>
        </td></tr>    
            
        <tr valign="top">
        	<td>
            
            <div  id="address"></div>
                   
            </td>
        	<td>
            Your order no is <span id="orderNo" style="background-color:#0099CC;  padding:5px"></span>. Please note it for future reference<br><br>
            A confirmation mail has been sent to : <span id="email"></span><br><br>
            <a href="#" onclick="submitform()"><span style="background-color:#0099CC;  padding:5px">click here</span></a> to download your order copy in pdf format 
            </td>
        </tr>
        <tr><td colspan="2" align="center"><br><h3>Thank you for chosing hambaa!</h3>
</td></tr>
       
     </table>
    
<table>
     <tr><td colspan="2"><br />
<a href="suggest.php"><span style="background-color:#0099CC;  padding:5px">Attend a small survey</span></a></td></tr>
 
</table>
 
</div>


   
</td>

</tr>
</table>



<br>

<div id="footer" > 


<table border="0" width="952" height=154 align="center" >
<tr>
<td >
<h1>My Hambaa</h1>
</td>
<td >
<h1>Shopping Policies</h1>
</td>
<td >
<h1>Payment Information</h1>
</td>
<td >
<h1>Contact Us</h1>
</td>
</tr>

<tr>
<td>
<a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';getShoppingCart1()">My Cart</a> |
<a href="about_us.php">My Order</a> |
<a href="about_us.php">FAQs</a>
</td>

<td >
<a href="about_us.php">Return Policy</a> |
<a href="about_us.php">Refund Policy</a> |
<a href="about_us.php">Terms and Conditions</a>
</td>

<td >
<a href="about_us.php">Payment Options: </a>COD
</td>

<td >
e-mail:
<a href="mailto:care@hambaa.com">care@hambaa.com</a>
</td>
</tr>

<tr align="center"><td colspan="4">
<hr />
&copy;2012 All Rights Reserved by <a href="index.php">www.hambaa.com</a>
</td></tr>
</table>
</div>
<form id="generatePdf" method="POST" target="_blank" >
<input type="hidden" id="pdfemail" name="pdfemail" />
<input type="hidden" id="pdforderid" name="pdforderid" />
</form>

</body>
</html>


